struct

RAW CAN decoding

懵懂的女人 提交于 2019-12-24 22:18:24
问题 I'm trying to import CAN data using a virtual CAN network and am getting strange results when I unpack my CAN packet of data. I'm using Python 3.3.7 Code: import socket, sys, struct sock = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) interface = "vcan0" try: sock.bind((interface,)) except OSError: sys.stderr.write("Could not bind to interface '%s'\n" % interface) fmt = "<IB3x8s" while True: can_pkt = sock.recv(16) can_id, length, data = struct.unpack(fmt, can_pkt) can_id &=

assigning a value within a char array pointer

[亡魂溺海] 提交于 2019-12-24 22:09:15
问题 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX40 40 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ Int40 *parseString(char *str) { Int40 *p; char *ptr; int i, len, value, ptrValue; printf("%s\n", str); for(i = 0; i < 40; i++) { if(str[i] == 'a') { printf("%c\n", str[i]); str[i] = '0'; printf("%c\n", str[i]); } } } int main(int argc, char *argv[]) { // char string[40] = " // char *str = string; Int40 *p; parseString(

Serialize a group of integers using cython

假如想象 提交于 2019-12-24 20:50:25
问题 I saw this sample code from the Pyrobuf page for serializing an integer ~3 times faster than via struct.pack : def ser2(): cdef int x = 42 return (<char *>&x)[:sizeof(int)] I was wondering how this could be done for a group of integers. I saw cython has int[:] and array.array types, but I still don't understand how do I take a list of integers for example, and get the same (but faster) result as via struct.pack('i', *num_list) . map() didn't seem work faster for me, and I'm wondering how this

how to access formbean class obj in jsp page

丶灬走出姿态 提交于 2019-12-24 20:25:57
问题 I want to access from bean object in jsp page. How to get that? I have formbean class with customername,date,amount,rate etc with setter() and getter() for the field members. I have data access class where i can get data for the bean class property from database and set data to formbean class object E.g.: class formbean{ String amount; String rate; public void setAmount(String amount) { this.amount=amount }; String getAmount() { return amount; } ... } class dao { public Formbean fetchcust() {

Put a struct as a generic covariant parameter

狂风中的少年 提交于 2019-12-24 20:18:01
问题 I've an Covariant interface, which is in an array of it's parent type. They are defined globally like this: //The interface/class public interface IMyType<out T>{} public class MyType<T>: IMyType<T>{ T value; MyType<T>(T initialValue){ value = initialValue; } } I tried this: IMyType< object>[] tt = new IMyType<object>[] { new MyType<String>( "test"), //Works fine new MyType<SomeOtherRandomClass>(new SomeOtherRandomClass()),//works fine new MyType<Int32>(12)//Doesn't work }; Even trying to

How to convert a tabular format or python dataframe-equivalent format to msgpack format in C++

感情迁移 提交于 2019-12-24 19:27:09
问题 (Please Note: I am not able to embed images here. I dont have enough points for that. Could anyone please help me with that.) I understand how to convert the struct corresponding to the following tablular format (Struct1) into msgpack format: Struct1 For this I use the following code: #include <sstream> #include <iostream> #include <msgpack.hpp> inline std::ostream& hex_dump(std::ostream& o, std::string const& v) { std::ios::fmtflags f(o.flags()); o << std::hex; o << "b\'"; for (auto c : v) {

struct.error: unpack requires a string argument of length 2

别说谁变了你拦得住时间么 提交于 2019-12-24 18:21:43
问题 I have this following code it works 64bit another computer but it does not work with mine and gives the fallowing error.I use Python 3.3 and the requiered libraries. I could not solve the problem please help. import matplotlib.pyplot as plt import binascii import numpy import struct array = [] out = open('output.txt','wb') a=int(input("Enter the first value:")) b=int(input("Enter the second value:")) with open("thefile.bin", "rb") as f: i=0 for i in range(0, a): byte = f.read(1) i=0 for i in

How to partially parse JSON using Go?

回眸只為那壹抹淺笑 提交于 2019-12-24 17:17:36
问题 I have the following json: { "app": { "name": "name-of-app", "version" 1 }, "items": [ { "type": "type-of-item", "inputs": { "input1": "value1" } } ] } The items[0].inputs change based on the items[0].type . Knowing that, is there a way to keep the inputs field a string? The idea is to use the type to call the right handler passing the inputs , and in there I would parse the inputs string using the right struct. Example: package main import ( "fmt" "encoding/json" ) type Configuration struct

why can't I use partial struct initialization for a malloced struct in C

自闭症网瘾萝莉.ら 提交于 2019-12-24 17:17:35
问题 Apperently in C99 you can simply initialize a statically allocated struct in this way struct sometype { int a; double b; }; sometype a = { .a = 0; }; Well, this does not apply to a struct on heap like this. struct sometype *a = malloc(sizeof(struct sometype)); *a = { .a = 0; }; With GCC 4.9.2, the compiler complained error: expected expression before '{' token I know this is silly, but is there any syntax or technical reason that I cannot do this? 回答1: There is a difference between struct

pack struct / avoid padding

≡放荡痞女 提交于 2019-12-24 16:52:55
问题 I have following struct: struct SkipListNode{ void *data; // 8 bytes uint8_t size; // 1 byte // 7 bytes padding here... void *next[1]; // dynamic array, 8 bytes each "cell" }; I am using malloc() and I am allocating more space than sizeof(SkipListNode) , so I am extending the next[] array. I want to avoid 7 bytes waste. I can completely remove size field, but then I should keep single NULL (8 bytes) at the end of the array. However this does not help reducing the size. Shall I use __