Skip to main content

Item

A generic data type used to pass and retrieve your data from Reboot standard libraries. For example, Item is used to enqueue and dequeue your data from Queues. It is not meant as a stand alone library, but rather a convenience type for marshalling and unmarshalling data.

There are three ways of formatting data for an Item.

  • Value represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values. A producer of value is expected to set one of that variants, absence of any variant indicates an error. This type is meant to represent all possible JSON values.
  • bytes is used to store a string of bytes.
  • Any wraps a protobuf message, for code that already has one.

Imports

To use Items in Python, import the library where you would like to use it. In Typescript, the type will be inferred.

from reboot.std.item.v1.item import Item

Since this is a data type that is not stored individually, you do not need a servicer for it.

Value

Value is the recommended way to use Item for structured data: anything you could express as JSON.

To marshal your data

  • in Python, you can use helper methods from reboot.protobuf
  • in TypeScript, you can use @bufbuild/protobuf.

You'll need the additional import:

from reboot.protobuf import (
as_bool,
as_dict,
as_int,
as_list,
as_str,
from_bool,
from_dict,
from_int,
from_list,
from_str,
)

Then you can use it to store and retrieve your data from Items as follows:

item = Item(value=from_bool(True))
print(as_bool(item.value))

item = Item(value=from_int(3))
print(as_int(item.value))

item = Item(value=from_str("apple"))
print(as_str(item.value))

item = Item(value=from_list(["a", "b", "c"]))
print(as_list(item.value))

item = Item(value=from_dict({"details": "details-go-here"}))
print(as_dict(item.value))

bytes

If your data is formatted as a string of bytes, you can directly store that into an Item.

item = Item(bytes=b"some-bytes")
print(item.bytes)

Any

If you already have a protobuf message, you can store it directly in an Item.

To pack and unpack from an Any protobuf,

  • in Python, you can use helper methods from reboot.protobuf
  • in TypeScript, you can use @bufbuild/protobuf v1.

You'll need the additional import:

from reboot.protobuf import pack, unpack

Then you can use it to store and retrieve your protobufs from Items as follows:

item = Item(any=pack(message))

unpacked_message = unpack(item.any, SomeMessage)