def serialize(entity: SpacyRequestData, builder: Builder) -> Any:
        text_offset = builder.CreateString(entity.text)
        SpacyRequestClass.SpacyRequestStartTypeVector(builder, len(entity.types))
        for x in reversed(entity.types):
            builder.PrependByte(x.value)
        types_offset = builder.EndVector(len(entity.types))

        SpacyRequestClass.SpacyRequestStart(builder)
        SpacyRequestClass.SpacyRequestAddText(builder, text_offset)
        SpacyRequestClass.SpacyRequestAddType(builder, types_offset)

        return SpacyRequestClass.SpacyRequestEnd(builder)
Beispiel #2
0
    def create_flatbuffer(self) -> Builder:
        builder = Builder(1000)
        name_dict = {}
        player_config_offsets = [
            pc.write_to_flatbuffer(builder, name_dict)
            for pc in self.player_configs
        ]
        MatchSettingsFlat.MatchSettingsStartPlayerConfigurationsVector(
            builder, len(player_config_offsets))
        for i in reversed(range(0, len(player_config_offsets))):
            builder.PrependUOffsetTRelative(player_config_offsets[i])
        player_list_offset = builder.EndVector(len(player_config_offsets))
        mutator_settings_offset = self.mutators.write_to_flatbuffer(builder)

        if self.game_map in game_map_dict:
            upk = game_map_dict[self.game_map]
            map_index = map_types.index(self.game_map)
        else:
            self.logger.info(
                f"Did not recognize {self.game_map}, hoping it's new or a custom map!"
            )
            upk = self.game_map
            map_index = -1
        upk_offset = builder.CreateString(upk)

        MatchSettingsFlat.MatchSettingsStart(builder)
        MatchSettingsFlat.MatchSettingsAddPlayerConfigurations(
            builder, player_list_offset)
        MatchSettingsFlat.MatchSettingsAddGameMode(
            builder, game_mode_types.index(self.game_mode))
        MatchSettingsFlat.MatchSettingsAddGameMap(builder, map_index)
        MatchSettingsFlat.MatchSettingsAddGameMapUpk(builder, upk_offset)
        MatchSettingsFlat.MatchSettingsAddSkipReplays(builder,
                                                      self.skip_replays)
        MatchSettingsFlat.MatchSettingsAddInstantStart(builder,
                                                       self.instant_start)
        MatchSettingsFlat.MatchSettingsAddMutatorSettings(
            builder, mutator_settings_offset)
        MatchSettingsFlat.MatchSettingsAddExistingMatchBehavior(
            builder,
            index_or_zero(existing_match_behavior_types,
                          self.existing_match_behavior))
        MatchSettingsFlat.MatchSettingsAddEnableLockstep(
            builder, self.enable_lockstep)
        MatchSettingsFlat.MatchSettingsAddEnableRendering(
            builder, self.enable_rendering)
        MatchSettingsFlat.MatchSettingsAddEnableStateSetting(
            builder, self.enable_state_setting)
        MatchSettingsFlat.MatchSettingsAddAutoSaveReplay(
            builder, self.auto_save_replay)
        ms_offset = MatchSettingsFlat.MatchSettingsEnd(builder)
        builder.Finish(ms_offset)
        return builder
Beispiel #3
0
def handle_tileset(ts: minidom.Node, objs: GameObjects,
                   builder: flatbuffers.Builder):
    firstgid = int(ts.getAttribute('firstgid'))
    for t in ts.getElementsByTagName('tile'):
        gid = int(t.getAttribute('id')) + firstgid
        name = os.path.basename(
            t.getElementsByTagName('image')[0].getAttribute('source'))
        fbname = builder.CreateString(name)
        FlatBuffGenerated.Tileinfo.TileinfoStart(builder)
        FlatBuffGenerated.Tileinfo.TileinfoAddName(builder, fbname)
        FlatBuffGenerated.Tileinfo.TileinfoAddGid(builder, gid)
        objs.tileinfo.append(FlatBuffGenerated.Tileinfo.TileinfoEnd(builder))
Beispiel #4
0
def _serialise_stringarray(builder: flatbuffers.Builder, data: np.ndarray,
                           source: int):
    string_offsets = [
        builder.CreateString(string_item) for string_item in reversed(data)
    ]
    ArrayStringStartValueVector(builder, len(data))
    for string_offset in string_offsets:
        builder.PrependSOffsetTRelative(string_offset)
    string_array_offset = builder.EndVector(len(data))
    ArrayStringStart(builder)
    ArrayStringAddValue(builder, string_array_offset)
    value_position = ArrayStringEnd(builder)
    LogData.LogDataStart(builder)
    LogData.LogDataAddSourceName(builder, source)
    LogData.LogDataAddValue(builder, value_position)
    LogData.LogDataAddValueType(builder, Value.ArrayString)
Beispiel #5
0
def simple_request(request_type, client_id=0, text=None, data=None):

    builder = Builder(50)

    if text is not None:
        text = builder.CreateString(text)

    # Create Simple Request Data
    SimpleRequestData.SimpleRequestDataStart(builder)
    SimpleRequestData.SimpleRequestDataAddType(builder, request_type)

    if text is not None:
        SimpleRequestData.SimpleRequestDataAddText(builder, text)

    if data is not None:
        SimpleRequestData.SimpleRequestDataAddData(
            builder,
            data,
        )

    contentOffset = SimpleRequestData.SimpleRequestDataEnd(builder)

    # Create Message Data
    MessageData.MessageDataStart(builder)

    MessageData.MessageDataAddVersion(
        builder, CreateProtocolVersion(builder, *PROTO_VERSION))

    MessageData.MessageDataAddSenderId(builder, client_id)

    MessageData.MessageDataAddContentType(builder, Content.SimpleRequestData)

    MessageData.MessageDataAddContent(builder, contentOffset)

    end = MessageData.MessageDataEnd(builder)
    builder.Finish(end)

    if os.environ.get("DEBUG_TRANSPORT"):
        print('->',
              "SimpleRequestData",
              "%-23s" % requestlookup[request_type],
              data,
              text,
              sep='\t')

    return set_file_identifier(builder.Output())
Beispiel #6
0
def handle_hidingspots_layer(g: minidom.Node, objs: GameObjects,
                             builder: flatbuffers.Builder):
    for o in g.getElementsByTagName('object'):
        x, y, rotation = get_pos(o)
        poly = 0
        width = 0
        height = 0
        isCircle = False

        if not o.getElementsByTagName('polygon'):
            width, height = get_dim(o)
            x += (math.cos(math.radians(rotation)) * width / 2.0 -
                  math.sin(math.radians(rotation)) * height / 2.0)
            y += (math.cos(math.radians(rotation)) * height / 2.0 +
                  math.sin(math.radians(rotation)) * width / 2.0)
            if o.getElementsByTagName('ellipse'):
                assertCircleness(o)
                isCircle = True
        else:
            polyverts = getPolygonVertices(o)
            FlatBuffGenerated.HidingSpot.HidingSpotStartPolyvertsVector(
                builder, len(polyverts))
            for v in polyverts:
                vert_x, vert_y = v.split(",")
                vert_x_f = float(vert_x) * GLOBAL_SCALE
                vert_y_f = float(vert_y) * GLOBAL_SCALE
                FlatBuffGenerated.Vec2.CreateVec2(builder, vert_x_f, vert_y_f)
            poly = builder.EndVector(len(polyverts))

        name = builder.CreateString(o.getAttribute('name'))

        FlatBuffGenerated.HidingSpot.HidingSpotStart(builder)
        pos = FlatBuffGenerated.Vec2.CreateVec2(builder, x * GLOBAL_SCALE,
                                                y * GLOBAL_SCALE)
        FlatBuffGenerated.HidingSpot.HidingSpotAddPos(builder, pos)
        FlatBuffGenerated.HidingSpot.HidingSpotAddRotation(builder, rotation)
        size = FlatBuffGenerated.Vec2.CreateVec2(builder, width * GLOBAL_SCALE,
                                                 height * GLOBAL_SCALE)
        FlatBuffGenerated.HidingSpot.HidingSpotAddSize(builder, size)
        FlatBuffGenerated.HidingSpot.HidingSpotAddIsCircle(builder, isCircle)
        FlatBuffGenerated.HidingSpot.HidingSpotAddPolyverts(builder, poly)
        FlatBuffGenerated.HidingSpot.HidingSpotAddName(builder, name)
        objs.hidingspots.append(
            FlatBuffGenerated.HidingSpot.HidingSpotEnd(builder))
Beispiel #7
0
def handle_objects_layer(g: minidom.Node, objs: GameObjects,
                         builder: flatbuffers.Builder):
    for o in g.getElementsByTagName('object'):
        x, y, rot = get_pos(o)
        width, height = get_dim(o)
        gid = int(o.getAttribute('gid'))
        hspotname = ""

        for prop in o.getElementsByTagName("property"):
            if prop.getAttribute("name") == "hspotName":
                hspotname = prop.getAttribute("value")
        hspotNameFb = builder.CreateString(hspotname)

        FlatBuffGenerated.Object.ObjectStart(builder)
        pos = FlatBuffGenerated.Vec2.CreateVec2(builder, x * GLOBAL_SCALE,
                                                y * GLOBAL_SCALE)
        FlatBuffGenerated.Object.ObjectAddPos(builder, pos)
        FlatBuffGenerated.Object.ObjectAddRotation(builder, rot)
        FlatBuffGenerated.Object.ObjectAddGid(builder, gid)
        size = FlatBuffGenerated.Vec2.CreateVec2(builder, width, height)
        FlatBuffGenerated.Object.ObjectAddSize(builder, size)
        FlatBuffGenerated.Object.ObjectAddHspotname(builder, hspotNameFb)
        objs.objects.append(FlatBuffGenerated.Object.ObjectEnd(builder))
Beispiel #8
0
    def serialize(self, builder: flatbuffers.Builder):
        method_name_offset = builder.CreateString(self.method_name)
        sink_offsets = []
        for name, sink in self._sinks.items():
            resource_offset = sink.serialize_data(builder, name)
            sink_offsets.append(resource_offset)

        source_offsets = []
        for name, source in self._sources.items():
            resource_offset = source.serialize_data(builder, name)
            source_offsets.append(resource_offset)

        fi.Start(builder)
        fi.AddName(builder, method_name_offset)

        _serialize_vector_table(builder=builder,
                                start_offset_vector=fi.StartSinksVector,
                                offsets=sink_offsets)

        _serialize_vector_table(builder=builder,
                                start_offset_vector=fi.StartSourcesVector,
                                offsets=source_offsets)
        return fi.End(builder)
Beispiel #9
0
def raw_read_message(client_id, read_tag, read_id, daq_offset, daq_scaling,
                     raw):
    builder = Builder(raw.size * 2 + 200)
    read_id_offset = builder.CreateString(read_id)
    raw_offset = builder.CreateNumpyVector(raw)

    # Create the ReadBlockData object.
    ReadBlockData.ReadBlockDataStart(builder)
    ReadBlockData.ReadBlockDataAddType(
        builder, ReadBlockType.ReadBlockType.PASS_FIRST_RAW_BLOCK)
    ReadBlockData.ReadBlockDataAddReadTag(builder, read_tag)
    ReadBlockData.ReadBlockDataAddBlockIndex(builder, 0)
    ReadBlockData.ReadBlockDataAddTotalBlocks(builder, 1)
    ReadBlockData.ReadBlockDataAddTotalSamples(builder, raw.size)
    ReadBlockData.ReadBlockDataAddDaqOffset(builder, daq_offset)
    ReadBlockData.ReadBlockDataAddDaqScaling(builder, daq_scaling)
    ReadBlockData.ReadBlockDataAddReadId(builder, read_id_offset)
    ReadBlockData.ReadBlockDataAddRawData(builder, raw_offset)

    content_offset = ReadBlockData.ReadBlockDataEnd(builder)

    # Create Message Data
    MessageData.MessageDataStart(builder)

    MessageData.MessageDataAddVersion(
        builder, CreateProtocolVersion(builder, *PROTO_VERSION))

    MessageData.MessageDataAddSenderId(builder, client_id)

    MessageData.MessageDataAddContentType(builder, Content.ReadBlockData)

    MessageData.MessageDataAddContent(builder, content_offset)

    end = MessageData.MessageDataEnd(builder)
    builder.Finish(end)

    return set_file_identifier(builder.Output())
Beispiel #10
0
    def to_fb(self, builder: flatbuffers.Builder):

        head_angle_arr = []
        lift_height_arr = []
        record_heading_arr = []
        turn_to_recorded_heading_arr = []
        body_motion_arr = []
        backpack_lights_arr = []
        face_animation_arr = []
        procedural_face_arr = []
        robot_audio_arr = []
        event_arr = []

        for keyframe in self.keyframes:
            fbkf = keyframe.to_fb(builder)
            if isinstance(keyframe, AnimHeadAngle):
                head_angle_arr.append(fbkf)
            elif isinstance(keyframe, AnimLiftHeight):
                lift_height_arr.append(fbkf)
            elif isinstance(keyframe, AnimRecordHeading):
                record_heading_arr.append(fbkf)
            elif isinstance(keyframe, AnimTurnToRecordedHeading):
                turn_to_recorded_heading_arr.append(fbkf)
            elif isinstance(keyframe, AnimBodyMotion):
                body_motion_arr.append(fbkf)
            elif isinstance(keyframe, AnimBackpackLights):
                backpack_lights_arr.append(fbkf)
            elif isinstance(keyframe, AnimFaceAnimation):
                face_animation_arr.append(fbkf)
            elif isinstance(keyframe, AnimProceduralFace):
                procedural_face_arr.append(fbkf)
            elif isinstance(keyframe, AnimRobotAudio):
                robot_audio_arr.append(fbkf)
            elif isinstance(keyframe, AnimEvent):
                event_arr.append(fbkf)
            else:
                raise RuntimeError("Unexpected keyframe type.")

        CozmoAnim.Keyframes.KeyframesStartHeadAngleKeyFrameVector(
            builder, len(head_angle_arr))
        for i in reversed(range(len(head_angle_arr))):
            builder.PrependUOffsetTRelative(head_angle_arr[i])
        head_angle_vector = builder.EndVector(len(head_angle_arr))

        CozmoAnim.Keyframes.KeyframesStartLiftHeightKeyFrameVector(
            builder, len(lift_height_arr))
        for i in reversed(range(len(lift_height_arr))):
            builder.PrependUOffsetTRelative(lift_height_arr[i])
        lift_height_vector = builder.EndVector(len(lift_height_arr))

        CozmoAnim.Keyframes.KeyframesStartRecordHeadingKeyFrameVector(
            builder, len(record_heading_arr))
        for i in reversed(range(len(record_heading_arr))):
            builder.PrependUOffsetTRelative(record_heading_arr[i])
        record_heading_vector = builder.EndVector(len(record_heading_arr))

        CozmoAnim.Keyframes.KeyframesStartTurnToRecordedHeadingKeyFrameVector(
            builder, len(turn_to_recorded_heading_arr))
        for i in reversed(range(len(turn_to_recorded_heading_arr))):
            builder.PrependUOffsetTRelative(turn_to_recorded_heading_arr[i])
        turn_to_recorded_heading_vector = builder.EndVector(
            len(turn_to_recorded_heading_arr))

        CozmoAnim.Keyframes.KeyframesStartBackpackLightsKeyFrameVector(
            builder, len(backpack_lights_arr))
        for i in reversed(range(len(backpack_lights_arr))):
            builder.PrependUOffsetTRelative(backpack_lights_arr[i])
        backpack_lights_vector = builder.EndVector(len(backpack_lights_arr))

        CozmoAnim.Keyframes.KeyframesStartBodyMotionKeyFrameVector(
            builder, len(body_motion_arr))
        for i in reversed(range(len(body_motion_arr))):
            builder.PrependUOffsetTRelative(body_motion_arr[i])
        body_motion_vector = builder.EndVector(len(body_motion_arr))

        CozmoAnim.Keyframes.KeyframesStartFaceAnimationKeyFrameVector(
            builder, len(face_animation_arr))
        for i in reversed(range(len(face_animation_arr))):
            builder.PrependUOffsetTRelative(face_animation_arr[i])
        face_animation_vector = builder.EndVector(len(face_animation_arr))

        CozmoAnim.Keyframes.KeyframesStartProceduralFaceKeyFrameVector(
            builder, len(procedural_face_arr))
        for i in reversed(range(len(procedural_face_arr))):
            builder.PrependUOffsetTRelative(procedural_face_arr[i])
        procedural_face_vector = builder.EndVector(len(procedural_face_arr))

        CozmoAnim.Keyframes.KeyframesStartRobotAudioKeyFrameVector(
            builder, len(robot_audio_arr))
        for i in reversed(range(len(robot_audio_arr))):
            builder.PrependUOffsetTRelative(robot_audio_arr[i])
        robot_audio_vector = builder.EndVector(len(robot_audio_arr))

        CozmoAnim.Keyframes.KeyframesStartEventKeyFrameVector(
            builder, len(event_arr))
        for i in reversed(range(len(event_arr))):
            builder.PrependUOffsetTRelative(event_arr[i])
        event_vector = builder.EndVector(len(event_arr))

        CozmoAnim.Keyframes.KeyframesStart(builder)
        CozmoAnim.Keyframes.KeyframesAddHeadAngleKeyFrame(
            builder, head_angle_vector)
        CozmoAnim.Keyframes.KeyframesAddLiftHeightKeyFrame(
            builder, lift_height_vector)
        CozmoAnim.Keyframes.KeyframesAddRecordHeadingKeyFrame(
            builder, record_heading_vector)
        CozmoAnim.Keyframes.KeyframesAddTurnToRecordedHeadingKeyFrame(
            builder, turn_to_recorded_heading_vector)
        CozmoAnim.Keyframes.KeyframesAddBodyMotionKeyFrame(
            builder, body_motion_vector)
        CozmoAnim.Keyframes.KeyframesAddBackpackLightsKeyFrame(
            builder, backpack_lights_vector)
        CozmoAnim.Keyframes.KeyframesAddFaceAnimationKeyFrame(
            builder, face_animation_vector)
        CozmoAnim.Keyframes.KeyframesAddProceduralFaceKeyFrame(
            builder, procedural_face_vector)
        CozmoAnim.Keyframes.KeyframesAddRobotAudioKeyFrame(
            builder, robot_audio_vector)
        CozmoAnim.Keyframes.KeyframesAddEventKeyFrame(builder, event_vector)
        kfs = CozmoAnim.Keyframes.KeyframesEnd(builder)

        name_str = builder.CreateString(self.name)

        CozmoAnim.AnimClip.AnimClipStart(builder)
        CozmoAnim.AnimClip.AnimClipAddName(builder, name_str)
        CozmoAnim.AnimClip.AnimClipAddKeyframes(builder, kfs)
        fbclip = CozmoAnim.AnimClip.AnimClipEnd(builder)

        return fbclip
Beispiel #11
0
    def serialize(data: MostSimilarRequestData, builder: flatbuffers.Builder):
        text = builder.CreateString(data.text)
        MostSimilarRequest.MostSimilarRequestStart(builder)
        MostSimilarRequest.MostSimilarRequestAddText(builder, text)

        return MostSimilarRequest.MostSimilarRequestEnd(builder)
Beispiel #12
0
def handle_meta_layer(g: minidom.Node, objs: GameObjects,
                      builder: flatbuffers.Builder):
    for o in g.getElementsByTagName('object'):
        x, y, rotation = get_pos(o)
        width, height = get_dim(o)

        typ = o.getAttribute('type')

        if typ == 'playerwall':
            x += (math.cos(math.radians(rotation)) * width / 2.0 -
                  math.sin(math.radians(rotation)) * height / 2.0)
            y += (math.cos(math.radians(rotation)) * height / 2.0 +
                  math.sin(math.radians(rotation)) * width / 2.0)

            FlatBuffGenerated.PlayerWall.PlayerWallStart(builder)
            pos = FlatBuffGenerated.Vec2.CreateVec2(builder, x * GLOBAL_SCALE,
                                                    y * GLOBAL_SCALE)
            FlatBuffGenerated.PlayerWall.PlayerWallAddPosition(builder, pos)
            size = FlatBuffGenerated.Vec2.CreateVec2(
                builder, width / 2.0 * GLOBAL_SCALE,
                height / 2.0 * GLOBAL_SCALE)
            FlatBuffGenerated.PlayerWall.PlayerWallAddSize(builder, size)
            FlatBuffGenerated.PlayerWall.PlayerWallAddRotation(
                builder, rotation)
            pwall = FlatBuffGenerated.PlayerWall.PlayerWallEnd(builder)
            objs.playerwalls.append(pwall)

        elif typ == 'waypoint':
            name = o.getAttribute('name')

            neighbors = []
            isspawn = False
            isplayerspawn = False

            assertCircleness(o)
            x += (math.cos(math.radians(rotation)) * width / 2.0 -
                  math.sin(math.radians(rotation)) * height / 2.0)
            y += (math.cos(math.radians(rotation)) * height / 2.0 +
                  math.sin(math.radians(rotation)) * width / 2.0)
            radius = (width / 2.0) * GLOBAL_SCALE

            for prop in o.getElementsByTagName('property'):
                prop_name = prop.getAttribute('name')
                value = prop.getAttribute('value')
                if prop_name == 'wps':
                    neighbors = value.split(',')
                elif prop_name == 'isspawn':
                    isspawn = (value == 'true')
                elif prop_name == 'isplayerspawn':
                    isplayerspawn = (value == 'true')
                else:
                    print("WARNING: Unknown property {}".format(prop_name))

            neighbors = list(filter(lambda x: x.strip() != "", neighbors))

            if len(neighbors) < 2 and not isplayerspawn and not isspawn:
                print("WARNING: waypoint {} has < 2 neighbors".format(name))

            name = builder.CreateString(name)
            neighOff = [builder.CreateString(x) for x in neighbors]
            FlatBuffGenerated.NavPoint.NavPointStartNeighborsVector(
                builder, len(neighOff))
            for b in neighOff:
                builder.PrependUOffsetTRelative(b)
            neighs = builder.EndVector(len(neighOff))
            FlatBuffGenerated.NavPoint.NavPointStart(builder)
            pos = FlatBuffGenerated.Vec2.CreateVec2(builder, x * GLOBAL_SCALE,
                                                    y * GLOBAL_SCALE)
            FlatBuffGenerated.NavPoint.NavPointAddPosition(builder, pos)
            FlatBuffGenerated.NavPoint.NavPointAddRadius(builder, radius)
            FlatBuffGenerated.NavPoint.NavPointAddName(builder, name)
            FlatBuffGenerated.NavPoint.NavPointAddNeighbors(builder, neighs)
            FlatBuffGenerated.NavPoint.NavPointAddIsspawn(builder, isspawn)
            FlatBuffGenerated.NavPoint.NavPointAddIsplayerspawn(
                builder, isplayerspawn)
            objs.navpoints.append(
                FlatBuffGenerated.NavPoint.NavPointEnd(builder))
    def serialize(data: EmbeddingRequestData, builder: flatbuffers.Builder):
        text = builder.CreateString(data.text)
        EmbeddingRequest.EmbeddingRequestStart(builder)
        EmbeddingRequest.EmbeddingRequestAddText(builder, text)

        return EmbeddingRequest.EmbeddingRequestEnd(builder)